#include <stdio.h>
#include <gtk/gtk.h>
#include "GTKIPV6_EDITOR.h"

char confstr1[] = "#\
# Sample configuration file for Miredo\n\
\n\
# Please refer to the miredo.conf(5) man page for details.\n\
\n\
# Miredo can safely run as a Teredo client, which is the default.\n\
#RelayType client\n\
\n\
# Name of the network tunneling interface.\n\
InterfaceName	teredo\n\
\n\
# Depending on the local firewall/NAT rules, you might need to force\n\
# Miredo to use a fixed UDP port and or IPv4 address.\n\
#BindPort	3545\n\
#BindAddress	192.0.2.100\n\
\n\
#SyslogFacility	user\n\
\n\
## CLIENT-SPECIFIC OPTIONS\n\
# The hostname or primary IPv4 address of the Teredo server.\n\
# This setting is required if Miredo runs as a Teredo client.\n\
#**************************************************************************#\n\
#      teredo.remlab.net is an experimental service for testing only.      #\n\
# Please use another server for production and/or large scale deployments. #\n\
#**************************************************************************#\n\
#ServerAddress teredo.ipv6.microsoft.com\n\
#ServerAddress teredo.ginzado.ne.jp\n\
#ServerAddress teredo.iks-jena.de\n\
#ServerAddress teredo.remlab.net\n\
#ServerAddress2 teredo2.remlab.net\n";

char confstr2[] = "## RELAY-SPECIFIC OPTIONS\n\
#Prefix 2001:0::\n\
#InterfaceMTU 1280\n";

char confstr_gipv6_header[] = "\n##GTKIPV6-EDITOR added\n";

char *serv = "ServerAddress teredo.remlab.net\n";

void setserv( GtkWidget *widget, gpointer data)
{
    gint iter;

    iter = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));

    switch(iter)
    {
        case 0:
            serv = "ServerAddress teredo.ipv6.microsoft.com\n";
            break;
        case 1:
            serv = "ServerAddress teredo.ginzado.ne.jp\n";
            break;
        case 2:
            serv = "ServerAddress teredo.iks-jena.de\n";
            break;
        case 3:
            serv = "ServerAddress teredo.remlab.net\n";
            break;
        case 4:
            serv = "ServerAddress2 teredo2.remlab.net\n";
            break;
        default:
            serv = "ServerAddress teredo.remlab.net\n";
            break;
    }

#ifdef DEBUG
    printf( "In setserv(),iter = %d\n", iter);
    printf( "In setserv(),serv = %s\n", serv);
    fflush(stdout);
#endif

    return;
}

void save_config()
{
    FILE *conf_new;

#ifdef DEBUG
    printf( "In save_config(),serv = %s\n", serv);
#endif

    //打开配置文件
    conf_new = fopen("/etc/miredo/miredo.conf", "w");
    if( conf_new == (FILE *)NULL )
    {
        fprintf( stderr, "open file conf_new in write mode err!");
        return;
    }

    fprintf( conf_new, "%s%s%s\n%s", confstr1, confstr_gipv6_header, serv, confstr2);
    printf("make configfile /etc/miredo/miredo.conf ok!\n");

    fclose(conf_new);
    gtk_main_quit();

    return;
}
